package com.jhy.product.entity;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serializable;
import java.util.Date;

import com.jhy.common.valid.AddGroup;
import com.jhy.common.valid.UpdateGroup;
import lombok.Data;
import org.hibernate.validator.constraints.URL;

import javax.validation.constraints.*;

/**
 * 品牌
 * 
 * @author jhy
 * @email 2496085873@qq.com
 * @date 2021-05-09 11:02:17
 */

//添加JSR303注解，做数据校验
//如果我们只是在前端做了数据校验，那么我们通过postman或其他工具绕过前端直接给服务器发请求就会出错
//通常：前后端都会进行数据校验
@Data
@TableName("pms_brand")
public class BrandEntity implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 * 品牌id --->添加时不能带品牌id(数据库自增),修改时必须带品牌id
	 */
	@Null(message = "添加时不能带品牌id",groups = AddGroup.class)
	@NotNull(message = "修改时必须带品牌id",groups = UpdateGroup.class) //group指定分组，用来分组校验
	@TableId
	private Long brandId;
	/**
	 * 品牌名 --->无论添加还是修改，品牌名必须带
	 */
	@NotBlank(message = "品牌名不能为空",groups = {AddGroup.class,UpdateGroup.class}) //非空并且至少包含一个字符
	private String name;
	/**
	 * 品牌logo地址  --->添加必须带logo地址，修改时如果不变，可以不带
	 */
	@NotEmpty(groups = AddGroup.class)
	@URL(message = "logo地址必须是一个地址",groups = {AddGroup.class,UpdateGroup.class}) //必须是一个url
	private String logo;
	/**
	 * 介绍
	 */
	private String descript;
	/**
	 * 显示状态[0-不显示；1-显示]
	 */
	@NotNull(groups = AddGroup.class)
	@Min(value = 0,message = "显示状态只能为0或者1",groups = {AddGroup.class,UpdateGroup.class})
	@Max(value = 1,message = "显示状态只能为0或者1",groups = {AddGroup.class,UpdateGroup.class})
	private Integer showStatus;
	/**
	 * 检索首字母--->自定义校验规则
	 */
	@NotNull(groups = AddGroup.class)
	@Pattern(regexp = "^[a-zA-Z]$",message = "首字母必须在a-z或者A-Z之间",
			groups = {AddGroup.class,UpdateGroup.class})
	private String firstLetter;
	/**
	 * 排序
	 */
	@NotNull(groups = AddGroup.class)
	@Min(message = "排序字段只能是正整数", value = 0,groups = {AddGroup.class,UpdateGroup.class})
	private Integer sort;

}
